/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> ret;
    vector<int> path;

    vector<vector<int>> pathSum(TreeNode* root, int targetSum) {
        dfs(root, targetSum);
        return ret;
    }
    void dfs(TreeNode* root, int targetSum)
    {
        if (root == nullptr) return;

        targetSum -= root->val;
        path.emplace_back(root->val);
        if (!root->left && !root->right && !targetSum) ret.emplace_back(path);
        dfs(root->left, targetSum);
        dfs(root->right, targetSum);
        path.pop_back();
    }
};

class Solution {
public:
    void wiggleSort(vector<int>& nums) {
        // sort(nums.begin(), nums.end());
        // vector<int> tmp = nums;
        // int n = nums.size();
        // int left = 0, right = n - 1;
        // for(int i = 0; i < n; i += 2)
        // {
        //     nums[i] = tmp[right];
        //     right--;
        // }
        // for(int i = 1; i < n; i+= 2)
        // {
        //     nums[i] = tmp[left];
        //     left++;
        // }
        int n = nums.size();
        for (int i = 1; i < n; i++)
        {
            if (i % 2 == 0)
            {
                if (nums[i] > nums[i - 1]) swap(nums[i], nums[i - 1]);
            }
            else
            {
                if (nums[i] < nums[i - 1]) swap(nums[i], nums[i - 1]);
            }
        }
    }
};